-
Notifications
You must be signed in to change notification settings - Fork 274
Bugfix/static function #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/static function #739
Conversation
src/goto-programs/goto_inline.cpp
Outdated
// We also don't allow for the _start function to have any of its | ||
// function calls to be inlined | ||
if(!goto_function.body_available() || | ||
f_it->first==ID__start) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use ID__start
directly, use goto_functions.entry_point()
instead.
@@ -149,7 +150,7 @@ void remove_internal_symbols( | |||
else if(is_function) | |||
{ | |||
// body? not local (i.e., "static")? | |||
if(has_body && !is_file_local) | |||
if(has_body || (!is_file_local && (config.main == symbol.name.c_str()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That logic appears wrong to me - shouldn't this code be:
if(has_body &&
(!is_file_local || config.main==symbol.name))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - & since this wasn't picked up by the tests I suggest adding an additional test that verifies an unused static function with body is correctly removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, after discussing it with @thk123 it appears that I had understood the initial condition wrong, and thought that we should include a function "if it has a body or ...". Thomas let me know that this is wrong, and that if it has no body it's useless to us, so you're right. It will be updated accordingly.
5b996c0
to
1a657b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the test would fail under the old logic.
regression/ansi-c/static4/main.c
Outdated
@@ -0,0 +1 @@ | |||
static int foo(int a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The symbol would still be included with the old logic since it is both static and without body. The function should have a body and should still be excluded.
df86a4c
to
dbcff69
Compare
@kroening Still left to decide whether this behaviour is actually desirable, i.e., whether functions marked "static" constitute valid entry points at all. |
@tautschnig Reason for needing this is for generating the test suite for a static function is useful when trying to generate unit tests. |
@thk123, how do you run these tests? |
@peterschrammel We talked with thk123 about it, and the simple solution is to include the .c file in the test (as we already do) if the function is static. |
@@ -149,7 +150,8 @@ void remove_internal_symbols( | |||
else if(is_function) | |||
{ | |||
// body? not local (i.e., "static")? | |||
if(has_body && !is_file_local) | |||
if(has_body && | |||
(!is_file_local || (config.main==symbol.name.c_str()))) | |||
get_symbols_rec(ns, symbol, exported); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the .c_str() doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kroening It's returning a const char *
that we can compare to the std::string
that is config.main
. Without it, we get the following error message:
remove_internal_symbols.cpp: In function 'void remove_internal_symbols(symbol_tablet&)':
remove_internal_symbols.cpp:153:54: error: no match for 'operator==' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'const irep_idt {aka const dstringt}')
if(has_body || (!is_file_local && (config.main == symbol.name)))
If we need to change it, I can change the c_str()
call to as_string()
, but they appear to do exactly the same thing, with the difference that c_str()
returns a C string whereas as_string()
returns a c++ string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kroening @NlightNFotis I'm wondering why config.main
is a string. I can't see a good reason for it not to be an irep_idt
.
<snip>
Paging @martin-cs to add some concerns he has and @tautschnig for reviewing the solution.
For the record...
I wondered why we were removing functions at this early stage and when
our general principle is to keep things as they are in the front-end and
then only transform when we actually need to. It occurred to me that
this was likely in the linker because it was implementing the semantics
of linking (which symbols are included in shared libraries, etc.). The
situation we want to support is clearly not something a C linker would
(directly) do but I worried that we might break something if we changed
the semantics.
Given the review this has had I have no particular concerns with the
current state of things, I just said I would comment on this.
|
Sorry, don't see why inlining into the _start function is a problem? |
@kroening Unfortunately the original PR for this change has been lost - but from memory and based off the commit message, the problem was to do with the interpreter not recording entering and exiting a function as it never entered the function. This commit is in test-gen-support so perhaps it shouldn't be back ported to CBMC? |
When the partial inlining comes to the _Start function, it skips over it. We don't want inlining on the start function because if we are trying to find the entry point for the users code, it is important it hasn't been inlined into GOTO generated code.
…elected as the entry point and changed the tests to CORE rather than KNOWNBUG
…n error when a symbol ambiguity due to static arises.
…nternal_symbols static condition.
dbcff69
to
62995f5
Compare
Greetings,
This pull request contains a fix for the issue reported in pr #718. This contains the fix, changes for the tests so that they are now active, along with two more tests that show that
goto-cc
now correctly reports ambiguity that arises due to usage of the qualifierstatic
between two functions with the same name and signature but in two different translation units.Paging @martin-cs to add some concerns he has and @tautschnig for reviewing the solution.